package ciyuan.Item.SkillBook;

import ciyuan.Item.ItemGroups;
import ciyuan.Item.TypeInterface.SkillBookType;
import ciyuan.Player.Skill.Passive.AddStar;
import ciyuan.Player.Skill.SkillUtils;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.DamageSource;
import net.minecraft.util.Hand;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TranslationTextComponent;

public class Charge extends SkillBookType {

    public Charge() {
        super(new Properties().tab(ItemGroups.SkillBook));
    }

    @Override
    public void keyDown(PlayerEntity playerEntity) {
        SkillUtils.setSkillColdInterval(playerEntity, this, 10 * 1000);

        //playerEntity.setDeltaMovement(new Vector3d(x,playerEntity.getY(),z).subtract(playerEntity.getX(),playerEntity.getY(),playerEntity.getZ()));
        playerEntity.knockback(1.5F, MathHelper.sin(playerEntity.yRot * ((float) Math.PI / 180F)), -MathHelper.cos(playerEntity.yRot * ((float) Math.PI / 180F)));
        playerEntity.swing(Hand.MAIN_HAND);
        playerEntity.sweepAttack();

        SkillUtils.addHitListener(playerEntity,this::onHit,40);
        SkillUtils.saveSkillCastTime(playerEntity,this);
    }

    public void onHit(PlayerEntity playerEntity, Entity target) {
        target.hurt(DamageSource.playerAttack(playerEntity),10F);
        AddStar.addCount(playerEntity);
    }

    @Override
    public String getSkillCastName() {
        return "charge";
    }

    @Override
    public ITextComponent getSkillDescription() {
        return new TranslationTextComponent("ciyuan.skill.desc.1");
    }

    @Override
    public ITextComponent getSkillName() {
        return new TranslationTextComponent("ciyuan.skill.name.1");
    }
}
